import 'package:flutter/material.dart';
import 'package:flutter_todo/common/app.request.dart';
import 'package:flutter_todo/models/todo/todo.model.dart';

class TodoListWiget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _TodoListWigetState();
}

class _TodoListWigetState extends State<TodoListWiget> {
  List<TodoModel> _todoList = [];

  @override
  void initState() {
    super.initState();
    _getTodoList();
  }

  /// 获取所有待办事项，并设置状态
  Future<void> _getTodoList() async {
    List<TodoModel> allTodo = await AppRequest().getAllTodo();
    setState(() {
      _todoList.addAll(allTodo);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
          '${_todoList.length > 0 ? _todoList.first.toJson() : _todoList}'),
    );
  }
}
